package com.sishu.controller;

import com.sishu.pojo.Questionlibrary;
import com.sishu.pojo.dto.Questionlibrarydto;
import com.sishu.service.QuestionlibraryService;
import com.sishu.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@SuppressWarnings("rawtypes")
@RestController
@Slf4j
@RequestMapping("/question/")
@CrossOrigin(origins = "*")
public class QuestionlibraryController {

    @Resource
    private QuestionlibraryService questionlibraryService;

    /**
     * @author linyi
     * @date 2025-01-09 14:14:30
     * @description 题库 controller
     */

    @GetMapping("getrandomquestion")  //随机获取一道题库中的题目
    public Result getrandomquestion(@Param("classification") String classification) {
        return questionlibraryService.getrandomquestion(classification);
    }


    @GetMapping("getrandomquestionbyclasshour") //随机获取一道当前课时的题库中的题目
    public Result getrandomquestionbyclasshour(@Param("classHour") Integer classHour, @Param("classification") String classification) {
        return questionlibraryService.getrandomquestionbyclasshour(classHour, classification);
    }

    @RequestMapping("answerrandomquestion")    //回答随机抽取的题目
    public Result answerrandomquestion(@Param("questionId") Integer questionId, @Param("answer") String answer) {
        return questionlibraryService.answerrandomquestion(questionId, answer);
    }


    @PostMapping("insertquestion")
    public Result insertquestion(@RequestBody List<Questionlibrary> questionlibrary) {
        log.info("questionlibrary:{}", questionlibrary);
        return questionlibraryService.insertquestion(questionlibrary);
    }

    @PostMapping("answerrevivequestion") //回答复活的题目
    public Result answerrevivequestion(@RequestBody List<Questionlibrarydto> answers) {
        log.info("answers = " + answers);
        return questionlibraryService.answerrevivequestion(answers);
    }

}
